<!DOCTYPE html>
<html lang="en" xmlns:th="https://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>登录页</title>

    <style>
        body {
            background-image: url("/backgroundImage.jpg");
            background-color: black;
            text-align: center;
        }

        .main {
            width: 40%;
            max-width: 500px;
            height: 400px;
            background-color: white;
            margin: 0 auto;
            margin-top: 150px;
            border-radius: 20px;
            transition: all 0.5s;
        }

        .registerMain {
            width: 40%;
            max-width: 500px;
            height: 450px;
            background-color: white;
            margin: 0 auto;
            margin-top: 150px;
            border-radius: 20px;
            transition: all 0.5s;
        }

        .buttonDiv {
            height: 100px;
            line-height: 100px;
            text-align: center;
        }

        button {
            width: 100px;
            height: 45px;
            border-radius: 10px;
            border: none;
            color: white;
            font-size: 1.5rem;
            transition: all 0.2s;
            margin: 0 5px;
        }

        button:hover {
            transform: scale(1.1);
        }

        .buttonDiv > :nth-child(1) {
            background-color: #eeb4be;
        }

        .buttonDiv > :nth-child(2) {
            background-color: #6abb91;
        }

        h1 {
            margin: 0;
            margin-bottom: 20px;
        }

        input {
            width: 85%;
            height: 35px;
            margin: 10px 0;
            border-radius: 10px;
            outline: 0 solid;
            border: 1px solid;
            transition: all 0.2s;
        }

        input:hover, input:focus {
            box-shadow: 0 0 30px pink;
            background-color: paleturquoise;
            transform: scale(1.05, 1.05);
        }

        input[type="submit"]:active {
            box-shadow: 0 0 10px yellow;
            background-color: pink;
            transform: scale(1, 1);
            transition: all 0.05s ease;
        }
    </style>

</head>
<body>

<div id="main" class="main">
    <div class="buttonDiv">
        <button onclick="changeToLogin()">登录</button>
        <button onclick="changeToRegister()">注册</button>
    </div>
    
    <h1>学校管理系统</h1>

    <form id="loginForm" th:action="@{/user/login}" method="post">
        <input type="text" name="username" placeholder="用户名">
        <input type="password" name="password" placeholder="密码">
        <input type="submit" value="登录">
        <p style="color: red" th:text="${loginMsg}"></p>
    </form>

    <form id="registerForm" th:action="@{/user/register}" method="post" style="display: none">
        <input type="text" name="username" placeholder="用户名">
        <input type="password" name="password" placeholder="密码">
        <input type="password" name="rePassword" placeholder="再次输入密码">
        <input type="submit" value="注册">
        <p style="color: red" th:text="${registerMsg}"></p>
    </form>
</div>

<script th:inline="javascript">
    // [[${registerMsg}]]
    if ([[${registerMsg}]]) {
        changeToRegister()
    }

    function changeToLogin() {
        const registerForm = document.getElementById('registerForm');
        registerForm.style.display = 'none';

        const loginForm = document.getElementById('loginForm');
        loginForm.style.display = 'block';

        const main = document.getElementById('main');
        main.className = 'main';
    }

    function changeToRegister() {
        const loginForm = document.getElementById('loginForm');
        loginForm.style.display = 'none';

        const registerForm = document.getElementById('registerForm');
        registerForm.style.display = 'block';

        const main = document.getElementById('main');
        main.className = 'registerMain';
    }
</script>
</body>
</html>